-
-
Notifications
You must be signed in to change notification settings - Fork 258
Pipeline Operator proposal #742
Conversation
src/tokenizer/index.js
Outdated
if (code === 124) { | ||
// '|>' | ||
if (next === 62) { | ||
this.expectPlugin("pipelineOperator"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we usually expect in the not-tokenizer part?
@@ -411,9 +411,17 @@ export default class Tokenizer extends LocationParser { | |||
const next = this.input.charCodeAt(this.state.pos + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is ok now
@@ -0,0 +1 @@ | |||
a |> b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More examples, especially arrows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@@ -61,7 +61,7 @@ export class TokenType { | |||
this.isAssign = !!conf.isAssign; | |||
this.prefix = !!conf.prefix; | |||
this.postfix = !!conf.postfix; | |||
this.binop = conf.binop || null; | |||
this.binop = conf.binop === 0 ? 0 : conf.binop || null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be nice with ?? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, should be easy to add/use here (would be good to find this kind of code on github/codebase and then do a codemod)
if (node.operator === "|>") { | ||
this.expectPlugin("pipelineOperator"); | ||
// Support syntax such as 10 |> x => x + 1 | ||
this.state.potentialArrowAt = startPos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the current draft spec has this logic. I couldn't figure out how to put it into the grammar. Right now, x |> y => z
would be a syntax error. But it's clearly useful--i'll think more about the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know tc39/proposal-pipeline-operator#60
Ref babel/proposals#29
Taken from babel/babel#3159 by @gilbert
Spec: https://github.com/tc39/proposal-pipeline-operator/pull/51/files
need more tests
10 |> x => x + 1;
a |> b |> c